/*
 *  Copyright (C) 2025 ameise <ameise.wang@gmail.com> - All Rights Reserved
 *
 *  This file is part of e3utils.
 *
 *  e3utils is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  e3utils is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with e3utils. If not, see <https://www.gnu.org/licenses/>.
 */

package uuid

import (
	"time"

	"github.com/google/uuid"
	"github.com/lithammer/shortuuid/v4"
	"github.com/rs/xid"
)

// github.com/rs/xid : 一定程度上避免了时钟回拨,但没有完全解决,和V7类似,带有时序性
// shortuuid:基于v4的改版

func New() string {
	return NewXid()
}

func NewXid() string {
	return xid.NewWithTime(time.Now().AddDate(-50, 0, 0)).String()
}

func NewXidWithTime(t time.Time) string {
	return xid.NewWithTime(t).String()
}

func NewShortV4() string {
	return shortuuid.NewWithEncoder(enc58)
}

func NewShortV7() string {
	s, _ := uuid.NewV7()
	return enc58.Encode(s)
}
